import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueCropper from 'vue-cropper';
import VideoPlayer from 'vue-video-player'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'
import '@/assets/icon/iconfont.css'

Vue.use(VideoPlayer)

// 引入路由
import router from './router';
// 引入状态管理
import store from './vuex/store';
// 引入Qs
import Qs from 'qs';
Vue.prototype.$qs = Qs;

Vue.config.productionTip = false
Vue.use(VueAxios, axios)
Vue.use(VueRouter)
Vue.use(ElementUI);
Vue.use(VueCropper)

import {getStore} from "./utils/util";
import {getCookie} from "./utils/util";
// 路由拦截器
router.beforeEach((to, from, next) => {
  if (to.matched.length != 0) {
    if (to.path.indexOf('/users') != -1) { // 判断该路由是否需要登录权限
      if (Boolean(getStore("userInfo"))) { // 通过vuex state获取当前的user是否存在
        next();
      } else {
        next({
          path: '/'// 将跳转的路由path作为参数，登录成功后跳转到该路由
        })
      }
    } else {
      next();
    }
  } else {
    next({
      path: '/error'// 将跳转的路由path作为参数，登录成功后跳转到该路由
    })
  }
})

// 过滤器
import * as custom from './utils/util'
Object.keys(custom).forEach(key => {
  Vue.filter(key, custom[key])
})
import * as AES from './utils/AesEncryptUtil'
Object.keys(AES).forEach(key => {
  Vue.filter(key, AES[key])
})

new Vue({
  render: h => h(App),
  router,
  store, //使用store vuex状态管理
  data: {
    // 空的实例放到根组件下，所有的子组件都能调用
    Bus: new Vue()
  }
}).$mount('#app')
